package cn.kgm.makeGodV2.condition;

import cn.kgm.makeGodV2.emotion.PersonalityTrait;
import lombok.Data;

import java.util.List;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-16 11:34
 * @Description: cn.kgm.makeGodV2.condition.LogicalCondition
 */
@Data
public class LogicalCondition implements Condition {
    @Override
    public boolean evaluate(PersonalityTrait traits) {
        switch (operator) {
            case AND:
                for (Condition cond : conditions) {
                    if (!cond.evaluate(traits)) return false;
                }
                return true;

            case OR:
                for (Condition cond : conditions) {
                    if (cond.evaluate(traits)) return true;
                }
                return false;

            case NOT:
                return !conditions.isEmpty() && !conditions.get(0).evaluate(traits);

            default:
                return false;
        }
    }

    private Operator operator;
    private List<Condition> conditions;

    public LogicalCondition(Operator operator, List<Condition> conditions) {
        this.operator = operator;
        this.conditions = conditions;
    }

    public enum Operator {AND, OR, NOT}
}
